var express = require('express');
var multer = require('multer');
var upload = express.Router();
var fs = require('fs');
var path = require('path');

var uploads = multer({dest: './upload'});

upload.post('/', uploads.single('logo'), function(req, res, next) {
    var file = req.file;
    res.send({
        body: {
            mimetype: file.mimetype, //文件类型
            originalName: file.originalname,  //原始文件名
            size: file.size,  //文件大小
            path: file.path  //保存路径
        },
        ret_code: '0'
    });
});

upload.get('/form', function(req, res, next) {
    var form = fs.readFileSync(path.join(__dirname, '../views/form.html'), {encoding: 'utf-8'});
    res.send(form);
});

module.exports = upload;